package com.hjx.other;


/**
 *        1
 *       / \
 *      2   3
 *    / \  / \
 *   4   5 6   7
 *
 * 二叉树转镜像树
 */
public class FanzhuanTree {

    public static void main(String[] args) {

        Node node1 = new Node(1);
        Node node2 = new Node(2);
        Node node3 = new Node(3);
        Node node4 = new Node(4);
        Node node5 = new Node(5);
        Node node6 = new Node(6);
        Node node7 = new Node(7);

        node1.setLeft(node2);
        node1.setRight(node3);

        node2.setLeft(node4);
        node2.setRight(node5);

        node3.setLeft(node6);
        node3.setRight(node7);

        new FanzhuanTree().fanzhuan(node1);
        System.out.println(11);
    }

    public void fanzhuan(Node node) {

        if (node == null) return;
        Node temp = node.left;
        node.left = node.right;
        node.right = temp;

        fanzhuan(node.left);
        fanzhuan(node.right);
    }
}

class Node {

    Node left;
    Node right;
    int value;

    public Node(int value) {
        this.value = value;
    }

    public Node(Node left, Node right, int value) {
        this.left = left;
        this.right = right;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public Node getLeft() {
        return left;
    }

    public void setLeft(Node left) {
        this.left = left;
    }

    public Node getRight() {
        return right;
    }

    public void setRight(Node right) {
        this.right = right;
    }
}